<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui">

    <h:form id="LeitfadenListForm">

        <p:panel header="#{bundle.ListLeitfadenTitle}">

            <p:dataTable id="datalist" value="#{leitfadenController.items}" var="item"
                         widgetVar="dataListNameForJavascript"
                         rowIndexVar="rowIndexNameForJavascript"
                         selectionMode="single" selection="#{leitfadenController.selected}"
                         rowKey="#{item.id}"
                         paginator="true"
                         rows="20"
                         rowsPerPageTemplate="10,20,30"
                         sortBy="#{item.kurzbezeichnung}"
                         sortFunction="#{alphanumComparator.compare}"
                         >

                <p:ajax event="rowSelect"   update="createButton viewButton editButton deleteButton printButton"/>
                <p:ajax event="rowUnselect" update="createButton viewButton editButton deleteButton printButton"/>

                <!--
                <p:column sortBy="#{item.id}" filterBy="#{item.id}">
                    <f:facet name="header">
                        <h:outputText value="#{bundle.ListLeitfadenTitle_id}"/>
                    </f:facet>
                    <h:outputText value="#{item.id}"/>
                </p:column>
                -->
                
                <p:column sortBy="#{item.kurzbezeichnung}" filterBy="#{item.kurzbezeichnung}" sortFunction="#{alphanumComparator.compare}">
                    <f:facet name="header">
                        <h:outputText value="#{bundle.ListLeitfadenTitle_kurzbezeichnung}"/>
                    </f:facet>
                    <h:outputText value="#{item.kurzbezeichnung}"/>
                </p:column>
                <p:column sortBy="#{item.name}" filterBy="#{item.name}"
                          styleClass="wrap">
                    <f:facet name="header">
                        <h:outputText value="#{bundle.ListLeitfadenTitle_name}"/>
                    </f:facet>
                    <h:outputText value="#{item.name}"/>
                </p:column>
                <p:column sortBy="#{item.beschreibung}" filterBy="#{item.beschreibung}"
                          styleClass="wrap">
                    <f:facet name="header">
                        <h:outputText value="#{bundle.ListLeitfadenTitle_beschreibung}"/>
                    </f:facet>
                    <h:outputText value="#{item.beschreibung}"/>
                </p:column>

                <p:column  styleClass="wrap">
                    <f:facet name="header">
                        <h:outputText value="Zugeordnete Rahmenbedingungen"/>
                    </f:facet>
                    
                    <ul onclick="dataListNameForJavascript.unselectAllRows(); dataListNameForJavascript.selectRow(#{rowIndexNameForJavascript})">
                    <ui:repeat value="#{item.rahmenbedingungCollection}" var="someObj" varStatus="loop">
                        <li>
                            #{someObj.kurzbezeichnung} 
                        </li>
                    </ui:repeat>
                    </ul>
                    
                </p:column>                
                
                <f:facet name="footer">
                    <p:commandButton id="createButton" icon="ui-icon-plus"   value="#{bundle.Create}" actionListener="#{leitfadenController.prepareCreate}" update=":LeitfadenCreateForm" oncomplete="LeitfadenCreateDialog.show()"/>
                    <p:commandButton id="viewButton"   icon="ui-icon-search" value="#{bundle.View}" update=":LeitfadenViewForm" oncomplete="LeitfadenViewDialog.show()" disabled="#{empty leitfadenController.selected}"/>
                    <p:commandButton id="editButton"   icon="ui-icon-pencil" value="#{bundle.Edit}" update=":LeitfadenEditForm" oncomplete="LeitfadenEditDialog.show()" disabled="#{empty leitfadenController.selected}"/>
                    <!-- Für Download von Reports ajax="false" http://stackoverflow.com/questions/13931999/send-a-pdf-to-browser-via-jsf -->
                    <p:commandButton id="printButton"  icon="ui-icon-print" actionListener="#{printController.printLeitfaden(leitfadenController.selected)}" ajax="false" value="#{bundle.Print}" disabled="#{empty leitfadenController.selected}">
                        <!--
                        <f:param name="leitfadenNr" value="#{leitfadenController.selected.id}" />
                        -->

                    </p:commandButton>
                    <p:commandButton id="deleteButton" icon="ui-icon-trash"  value="#{bundle.Delete}" actionListener="#{leitfadenController.delete}" update=":growl,datalist" disabled="#{empty leitfadenController.selected}" 
                                     style=" margin-left: 60px" immediate="true" />
                </f:facet>

            </p:dataTable>

        </p:panel>

    </h:form>

</ui:composition>